//创建用户相关的小仓库
import { defineStore } from "pinia";
//引入请求函数
import { reqSelfDevice, reqStatistic, reqLog, reqRecords, reqCurrent, reqHardware, reqStatisticSearch, reqDetailsImg } from "@/api/details/details";
// 引入组件库
import { ElMessage } from "element-plus";

/**
 * 用户信息
 * @methods  获取设备信息
 */
export const useDetailsStore = defineStore("detailsStore", {
  state: () => ({
    details: <any>[],   //所有设备的卡片式综合数据
    statisticDataSource: <any>[],
    statisticChartSource: <any>[],
    loginfo: <any>[],
    recordsDataSource: <any>[],//检测记录
    CheckNameListSource: [],
    SearchCheckNameList: <any>[], //统计检索的表格遍历
    SearchDataSource: [],//统计检索的表格数据
    SearchTotalRecords: '',//统计检索的总条数
    TotalRecords: "",
    currentList: <any>[],
    maxProductionEfficiency: "",   //最大生产效率
    hardwareReportTime: [], // 硬件状态的上报时间
    hardwareCPUsUsage: [], // CPU使用率
    hardwareGPUsUsage: [], // GPU使用率
    hardwareDiskUsage: [],  // 硬盘使用率
    hardwareMemoryUsage: [],  // 内存使用率
    hardwareNetworkUsage: [],  // 网络使用率
    hardwareInfo: {}, //硬件状态的总体数据，
    ImgList: [],//检测记录的图片
  }),
  //书写小仓库方法的地方
  actions: {
    async selfdevice(terminalIdentity: any) {
      try {
        let res: any = await reqSelfDevice(terminalIdentity);
        // 进行仓库存储
        this.details = res;
      } catch (error) {
        console.log(error);

      }
    },

    //获取所有设备的卡片式综合数据  
    async statistic(terminalIdentity: any, TemplateId: any) {
      try {
        let res: any = await reqStatistic(terminalIdentity, TemplateId);
        this.statisticDataSource = res.DataSource
        this.statisticChartSource = res.ChartSource
        this.maxProductionEfficiency = res.MaxProductionEfficiency
      } catch (error) {
        console.log(error);
      }
    },

    //统计检索
    async StatisticSearch(data: any) {
      try {
        let res: any = await reqStatisticSearch(data);
        this.SearchCheckNameList = res.CheckNameList
        this.SearchDataSource = res.DataSource
        this.SearchTotalRecords = res.TotalRecords
      } catch (error) {
        console.log(error);
      }
    },

    //检索指定设备的检测记录
    async records(data: any) {
      try {
        let res: any = await reqRecords(data);
        this.CheckNameListSource = res.CheckNameList
        this.recordsDataSource = res.DataSource
        this.TotalRecords = res.TotalRecords
      } catch (error) {
        console.log(error);
      }
    },

    //检索指定设备日志信息
    async logMessage(data: any) {
      try {
        let res: any = await reqLog(data);
        this.loginfo = res
      } catch (error) {
        console.log(error);
      }
    },

    //硬件状态=-----根据查询参数获取指定设备硬件状态的时间窗口数据
    async hardware(data: any) {
      try {
        let res: any = await reqHardware(data);
        this.hardwareReportTime = res.ReportTime
        this.hardwareCPUsUsage = res.CPUsUsage
        this.hardwareGPUsUsage = res.GPUsUsage
        this.hardwareDiskUsage = res.DiskUsage
        this.hardwareMemoryUsage = res.MemoryUsage
        this.hardwareNetworkUsage = res.NetworkUsage
        this.hardwareInfo = res
      } catch (error) {
        console.log(error);
      }
    },

    //根据模板编号查询生产批次信息
    async current(TemplateId: any) {
      try {
        let res: any = await reqCurrent(TemplateId);
        this.currentList = res
      } catch (error) {
        console.log(error);
      }
    },
    // 根据dataIdentifier、terminalIdentity获取检测记录视图
    async getImgs(TemplateId: any, dataIdentifier: any) {
      try {
        let res: any = await reqDetailsImg(TemplateId, dataIdentifier);
        this.ImgList = res
      } catch (error) {
        console.log(error);
      }
    }
  },
});
